var j$ = jQuery;
var readyToLoad = true,
    loadUrl = '';
    loadTimes = 0;
    loadContent = '',
    csrf = j$("#content").attr("data-csrf"),
    targetType = j$("#content").data("type"),
    targetId = j$("#content").data("id"),
    column = j$("#content").attr("data-column");

var initWishToBeenToStatus = function () {
    var has_been_to = j$("#content").data("been-to");
    var has_wish_to = j$("#content").data("wish-to");
    if ( has_been_to != "0" ) {
        j$("#hero-info-status-beento").addClass("hero-info-status-beento-active");
    }
    if ( has_wish_to == "True" ) {
        j$("#hero-info-status-wishto").addClass("hero-info-status-wishto-active");
    }
};

var initWishToBeenToEvents = function () {
    j$(".hero-info-status").on("click", "a", function(e) {
        e.preventDefault();
        var _btn = j$(this);
        var _method = _btn.attr("data-method");
        var _url;
        var _active = _btn.hasClass("hero-info-status-" + _method + "-active");
        if ( _active ) {
            _url = _method + "/cancel/";
        }else{
            _url = _method + "/add/";
        }
        _url = "/scenic/" + targetType + "/" + targetId + "/" + _url;
        if (!BT_USER_ID) {
            bt.misc.redirect_to_login(function () {
                j$.ajax({url: _url,dataType: 'json',type: 'GET'});
            });
            return false;
        }
        if ( _active ) {
            _btn.removeClass("hero-info-status-" + _method + "-active");
            bt.misc.modifyCount(_btn.find("b"), -1);
        }else{
            _btn.addClass("hero-info-status-" + _method + "-active");
            bt.misc.modifyCount(_btn.find("b"), 1);
        }
        j$.ajax({
            url: _url,
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                if (!data.success) {
                    if ( _active ) {
                        _btn.addClass("hero-info-status-" + _method + "-active");
                        bt.misc.modifyCount(_btn.find("b"), 1);
                    }else{
                        _btn.removeClass("hero-info-status-" + _method + "-active");
                        bt.misc.modifyCount(_btn.find("b"), -1);
                    }
                }
            }
        });
    });
};

var initNavEvents = function () {
    var _winscroll;
    j$(window).on("scroll", function(event) {
        _winscroll = j$(window).scrollTop();
        if (_winscroll >= 563 ){
            j$("#wrap").addClass("nav-fixed");
        }else{
            j$("#wrap").removeClass("nav-fixed");
        }
    });
};

var adjustImg = function(img) {
    var _width = j$(document).width();
    var _height = j$("#hero-header").height();
    var _h = j$(img).height();
    var _offset = (_height - _h) / 2;
    j$(img).width(_width).css("top", _offset);
};

var initSliderTransition = function() {
    j$("#hero-header").find("img").on("load", function(e) {
        if ( !j$(this).parent("li").hasClass("cur") ) {
            j$(this).hide();
        }
    });
    j$("#hero-thumb").on("click", ".hero-thumb-slider", function(e) {
        if ( j$(this).hasClass("cur") ) return;
        e.preventDefault();
        var _img = j$("#hero-header").find("li");
        var _currentImg = j$("#hero-header").find(".cur");
        var _index = j$(this).index();
        j$(this).addClass("cur").siblings("li").removeClass("cur");
        j$(_currentImg).removeClass("cur").fadeOut("500").css("zIndex", 0);
        j$("#hero-header").find("li").eq(_index).addClass("cur").css("zIndex", 51).fadeIn("500", function() {
            j$(this).css("zIndex", 50);
        });
    });
};

var getMorePhotos = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.photos.length === 0 ) {
                j$("#scenic-empty").show();
            }else{
                j$("#scenic-empty").hide();
            }
            loadContent = '';
            j$.each(data.photos, function(i, val) {
                loadContent += '<li><span><i></i>'+ val.recommendations
                         + '</span><a style="background-image: url('+ val.photo
                         + '); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ val.photo
                         + '\',sizingMethod=\'scale\');" title="'+ val.trip_name
                         + '" href="'+ val.url
                         + '"></a></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) { loadPhotos(); }
            loadTimes ++;
        }
    });
};

var loadPhotos = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#photos-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMorePhotos(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var getMoreTrips = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.trips.length === 0 ) {
                j$("#scenic-empty").show();
            }else{
                j$("#scenic-empty").hide();
            }
            loadContent = '';
            j$.each(data.trips, function(i, val) {
                loadContent += '<li><a target="_blank" title="'+ val.name
                            + ' by '+ val.username
                            + '" href="/trips/'+ val.encrypt_id
                            + '/"><div class="single-trip-pic"><ol>';
                j$.each(val.covers, function(c, cover) {
                    loadContent += '<li style="background-image: url('+ cover +'); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+ cover +'\',sizingMethod=\'scale\');"></li>';
                });
                loadContent += '</ol><dl class="single-trip-info"><dt class="one-row-ellipsis"><b>'+ val.name
                            + '</b><span><i>by</i>'+ val.username
                            + '</span></dt><dd class="one-row-ellipsis"><span>行程：<b>'+ val.day_count
                            + '</b>天</span><span>路径：';
                j$.each(val.cities, function(i, val) {
                    if ( i === 0 ) {
                        loadContent += val;
                    }else{
                        loadContent += '<i>&gt;</i>' + val;
                    }
                });
                loadContent += '</span></dd></dl><p class="single-trip-left"><i class="icons"></i></p><p class="single-trip-right"><i class="icons"></i></p></div>'
                            + '<p class="single-trip-data"><span>里程<b>'+ val.mileage
                            + 'Km</b></span><span>足迹<b>'+ val.wapoint_count
                            + '</b></span><span>浏览<b>'+ val.pv_count
                            + '</b></span><span>收藏<b>'+ val.recommendations
                            + '</b></span><span class="single-trip-comment">评论<b>'+ val.comment_count
                            + '</b></span></p>'
                            + '</a></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) { loadTrips(); }
            loadTimes ++;
        }
    });
};

var loadTrips = function () {
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#trips-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreTrips(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var initTripCoversEvents = function () {
    j$("#trips-list").on("click", ".single-trip-left", function(e) {
        var _ol = j$(this).parent(".single-trip-pic").find("ol");
        _ol.animate({left: "+="+640}, 500, function () {
            _refreshTripCoverBtn(_ol);
        });
        e.preventDefault();
    });
    j$("#trips-list").on("click", ".single-trip-right", function(e) {
        var _ol = j$(this).parent(".single-trip-pic").find("ol");
        _ol.animate({left: "-="+640}, 500, function () {
            _refreshTripCoverBtn(_ol);
        });
        e.preventDefault();
    });
    var _refreshTripCoverBtn = function (ol) {
        var _leftbtn = ol.parent(".single-trip-pic").find(".single-trip-left"),
            _rightbtn = ol.parent(".single-trip-pic").find(".single-trip-right");
        if ( ol.position().left >= 0 ) {
            _leftbtn.hide();
        }else if ( ol.position().left <= -1280 ) {
            _rightbtn.hide();
        }else{
            _rightbtn.show();
            _leftbtn.show();
        }
    };
};

var getMoreCities = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.cities.length === 0 ) {
                j$("#scenic-empty").show();
                j$("#poi-list").hide();
            }else{
                j$("#scenic-empty").hide();
                j$("#poi-list").show();
            }
            loadContent = '';
            j$.each(data.cities, function(i, val) {
                loadContent +='<li><a title="'+ val.name +'" target="_blank" href="'+ val.url
                            + '" class="cover" style="background-image: url(';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent += '); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent += '\',sizingMethod=\'scale\');"><div class="name"><h3 class="one-row-ellipsis">'+ val.name
                            + ' </h3></div>';
                loadContent +='</a><p class="tool"><a target="_blank" href="'+ val.url
                            + '">去过<b>'+ val.beento_count
                            + ' </b></a><i>&nbsp;</i><a target="_blank" href="'+ val.url
                            + '">想去<b>'+ val.wishto_count
                            + '</b></a></p></a></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) { loadCities(); }
            loadTimes ++;
        }
    });
};

var loadCities = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#cities-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreCities(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var getMoreSights = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.sights.length === 0 ) {
                j$("#scenic-empty").show();
                j$("#poi-list").hide();
            }else{
                j$("#scenic-empty").hide();
                j$("#poi-list").show();
            }
            loadContent = '';
            j$.each(data.sights, function(i, val) {
                loadContent +='<li><a style="background-image: url(';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='\',sizingMethod=\'scale\');" title="'+ val.name
                            + '" target="_blank" href="'+ val.url
                            + '" data-lng="'+ val.longitude
                            + '" data-lat="'+ val.latitude
                            + '" class="cover"><div class="name"><h3 class="one-row-ellipsis">'+ val.name
                            + '</h3></div></a><a target="_blank" href="'+ val.url
                            + '">';
                if ( val.description !== '' ) {
                    loadContent += '<p class="descripe">' + val.description;
                }else{
                    loadContent += '<p class="descripe nope">此处暂无具体描述，我们会尽快完善！';
                }
                loadContent +='<b class="descripe-ellipsis">...</b>'
                            + '</p></a><p class="tool"><a target="_blank" href="'+ val.url
                            + '">去过<b>'+ val.visited_count
                            + ' </b></a><i>&nbsp;</i><a target="_blank" href="'+ val.url
                            + '">想去<b>'+ val.wish_to_go_count
                            + '</b></a></p></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) {
                loadSights();
                j$("#poi-loading").hide();
            }
            loadTimes ++;
        }
    });
};

var loadSights = function (){
    if ( readyToLoad ) {
        var content = j$(loadContent);
        var t = $('<div style="position: absolute; top: 0; left: 110%;"></div>');
        t.append(content);
        $("body").append(t);

        t.find(".descripe").each(function(){
            var e = $(this);
            if(e.height() > 52){
                e.addClass("too-long");
            }
        })

        $("#poi-list").append(content);
        t.remove();
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreSights(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var getMoreFoods = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.foods.length === 0 ) {
                j$("#scenic-empty").show();
                j$("#poi-list").hide();
            }else{
                j$("#scenic-empty").hide();
                j$("#poi-list").show();
            }
            loadContent = '';
            j$.each(data.foods, function(i, val) {
                loadContent +='<li><a style="background-image: url(';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='\',sizingMethod=\'scale\');" title="'+ val.name
                            + '" target="_blank" href="'+ val.url
                            + '" data-lng="'+ val.longitude
                            + '" data-lat="'+ val.latitude
                            + '" class="cover"><div class="name"><h3 class="one-row-ellipsis">'+ val.name
                            + ' </h3></div></a><p class="tool"><a target="_blank" href="'+ val.url
                            + '">去过<b>'+ val.beento_count
                            + ' </b></a><i>&nbsp;</i><a target="_blank" href="'+ val.url
                            + '">想去<b>'+ val.wishto_count
                            + '</b></a></p></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) {
                loadFoods();
                j$("#poi-loading").hide();
            }
            loadTimes ++;
        }
    });
};

var loadFoods = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#poi-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreFoods(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var getMoreHotels = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.hotels.length === 0 ) {
                j$("#scenic-empty").show();
                j$("#poi-list").hide();
            }else{
                j$("#scenic-empty").hide();
                j$("#poi-list").show();
            }
            loadContent = '';
            j$.each(data.hotels, function(i, val) {
                loadContent +='<li><a style="background-image: url(';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='\',sizingMethod=\'scale\');" title="'+ val.name
                            + '" target="_blank" href="'+ val.url
                            + '" class="cover"><div class="name"><h3 class="one-row-ellipsis">'+ val.name
                            + ' </h3></div></a><p class="tool"><a target="_blank" href="'+ val.url
                            + '">去过<b>'+ val.beento_count
                            + ' </b></a><i>&nbsp;</i><a target="_blank" href="'+ val.url
                            + '">想去<b>'+ val.wishto_count
                            + '</b></a></p></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) {
                loadHotels();
                j$("#poi-loading").hide();
            }
            loadTimes ++;
        }
    });
};

var loadHotels = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#poi-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreHotels(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var getMoreMalls = function (url) {
    j$.ajax({
        url: url,
        dataType: 'json',
        success: function(data){
            if ( data.mall.length === 0 ) {
                j$("#scenic-empty").show();
                j$("#poi-list").hide();
            }else{
                j$("#scenic-empty").hide();
                j$("#poi-list").show();
            }
            loadContent = '';
            j$.each(data.mall, function(i, val) {
                loadContent +='<li><a style="background-image: url(';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='); -ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'';
                if ( val.cover !== '' ) {
                    loadContent += val.cover;
                }else{
                    loadContent += '/static/img/default_trip_cover_508px.png';
                }
                loadContent +='\',sizingMethod=\'scale\');" title="'+ val.name
                            + '" target="_blank" href="'+ val.url
                            + '" class="cover"><div class="name"><h3 class="one-row-ellipsis">'+ val.name
                            + ' </h3></div></a><p class="tool"><a target="_blank" href="'+ val.url
                            + '">去过<b>'+ val.beento_count
                            + ' </b></a><i>&nbsp;</i><a target="_blank" href="'+ val.url
                            + '">想去<b>'+ val.wishto_count
                            + '</b></a></p></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) {
                loadMalls();
                j$("#poi-loading").hide();
            }
            loadTimes ++;
        }
    });
};

var loadMalls = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#poi-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreMalls(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var initDropdownEvents = function () {
    var _dropdown = j$("#dropdown"),
        _choosebtn = j$("#choose-class"),
        _nav = j$("#dropdown-menu"),
        _navup = j$("#dropdown-nav-up"),
        _navdown = j$("#dropdown-nav-down"),
        _length = _nav.find("li").length,
        _singleHeight = 41;
    var _initArrowEvent = function () {
        _navdown.on("click", function(e) {
            e.preventDefault();
            _nav.animate({top: "-="+_singleHeight}, 100, function () {
                _refreshArrowBtn();
            });
        });
        _navup.on("click", function(e) {
            e.preventDefault();
            _nav.animate({top: "+="+_singleHeight}, 100, function () {
                _refreshArrowBtn();
            });
        });
    };
    var _refreshArrowBtn = function () {
        if ( _length > 8 ) {
            _navdown.show();
        }
        if ( _nav.position().top + _nav.height() < _dropdown.height() ) {
            _navdown.hide();
        }else{
            _navdown.show();
        }
        if ( _nav.position().top < 0 ) {
            _navup.show();
        }else{
            _navup.hide();
        }
    };
    var _changeMapURL = function (type, id, channel) {
        var _btn = j$("#gotomap");
        var _url = "/scenic/"+ type +"/"+ id +"/map/#"+ channel;
        _btn.attr('href', _url);
    };
    _initArrowEvent();
    _choosebtn.on("mouseover", function(e) {
        e.preventDefault();
        if ( (targetType == 1 || targetType == 2) || column == "tips" ) {
            _dropdown.slideDown("fast", function () {
                if ( column !== "tips" ) { _refreshArrowBtn(); }
            });
            _dropdown.on("mouseleave", function(e) {
                e.preventDefault();
                _dropdown.slideUp("fast");
                _dropdown.off("mouseleave");
            });
        }
    });
    _nav.on("click", "a", function(e) {
        e.preventDefault();
        var _name = j$(this).find("span").text();
        var _type = j$(this).data('type');
        var _id = j$(this).data('id');
        j$(this).parent("li").addClass("cur").siblings("li").removeClass("cur");
        loadUrl = "/scenic/"+ _type +"/"+ _id +"/"+ column +"/more/";
        loadTimes = 0;
        j$("#poi-list").empty();
        j$("#poi-loading").show();
        switch ( column ){
            case "sight":{
                getMoreSights(loadUrl);
            }
            break;
            case "food":{
                getMoreFoods(loadUrl);
            }
            break;
            case "hotel":{
                getMoreHotels(loadUrl);
            }
            break;
            case "mall":{
                getMoreMalls(loadUrl);
            }
            break;
            case "tips":{
                var _type = j$("#content").attr("data-type"),
                    _id = j$("#content").attr("data-id"),
                    _tag = j$(this).attr("data-tag");
                j$(this).parent("li").siblings(".last").remove();
                filterTips( _type, _id, _tag);
                if ( _name !== "全部贴士" ) {
                    _name += "贴士";
                }
            }
            break;
        }
        _choosebtn.text(_name);
        _dropdown.hide();
        _changeMapURL( _type, _id, column);
    });
};

var getMoreTips = function (url, tag) {
    var _tag = tag || "";
    j$.ajax({
        url: url,
        //data: {tag: _tag},
        dataType: 'json',
        success: function(data){
            if ( data.tips.length === 0 ) {
                j$("#scenic-empty").show();
            }else{
                j$("#scenic-empty").hide();
            }
            loadContent = '';
            j$.each(data.tips, function(i, tip) {
                loadContent +='<li data-id="'+ tip.id
                            + '"><div class="tips-info fn-clear"><a target="_blank" href="/u/'+ tip.user.id
                            + '/" class="tips-pic"><img src="'+ tip.user.avatar_m
                            + '" alt=""></a><div class="tips-user"><p><a target="_blank" href="/u/'+ tip.user.id
                            + '/">'+ tip.user.name 
                            + '</a></p>' + (bt.context('is_staff')?('<p style="font-size:16px;color:#5c5c5c;">( tipsid:'+tip.id + ' 员工可见 )</p>'):' ')
                            + '<p>'+ tip.datetime
                            + '</p></div><a href="###" data-like="'+ (tip.liked ? 'True' : 'False')
                            + '" class="tips-tool '+ (tip.liked ? 'tips-tool-active' : '')
                            + '"><span></span><b>'+ tip.liked_count
                            + '</b></a></div><p class="tips-text">'+ tip.content
                            + '</p><p class="tip-tags">';
                j$.each(tip.tags, function(j, tag) {
                    loadContent += '<a data-id="'+tag.id+'" class="btn" href="###">'+tag.name+'</a>';
                });
                if ( BT_USER_ID !== null && BT_USER_ID == tip.user.id ) {
                    loadContent +='<a class="tip-del" href="###">删除贴士</a>';
                }
                loadContent +='</p></li>';
            });
            readyToLoad = true;
            if ( data.more ) {
                j$("#load-more").data('more', 1);
            }else{
                j$("#load-more").data('more', 0);
            }
            loadUrl = data.next_url;
            if ( loadTimes === 0 ) {
                loadTips();
                j$("#poi-loading").hide();
            }
            loadTimes ++;
        }
    });
};

var loadTips = function (){
    if ( readyToLoad ) {
        j$(loadContent).appendTo("#tips-list");
    }
    readyToLoad = false;
    if ( j$("#load-more").data('more') ) {
        j$("#load-more").css('display', 'block');
        getMoreTips(loadUrl);
    }else{
        j$("#load-more").hide();
    }
};

var addNewTags = function () {
    j$("#tips-popup-tag-new").on("click", "a", function(e) {
        e.preventDefault();
        var _input = j$("#tips-popup-tag-new").find("input"),
            _re = /\s*,\s*/,
            _taglist = _input.val().split(_re);
        _taglist = bt.misc.unique(_taglist);
        j$.each(_taglist, function(i, val) {
            if ( val !== "" ) {
                var _content = '<a data-new="1" class="btn btn-primary" href="###">'+ val +'</a>';
                j$("#tips-popup-tag-other").before(_content);
            }
        });
        _input.val("");
        j$("#tips-popup-tag-new").fadeOut();
        j$("#tips-popup-tag-other").fadeIn();
    });
};

var filterTips = function (type, id, tag) {
    loadUrl = "/scenic/"+ type +"/"+ id +"/tips/more/" + (tag ? "?&tag=" + tag : "");
    loadTimes = 0;
    j$("#tips-list").empty();
    j$("#tag"+ tag).siblings(".last").remove();
    getMoreTips(loadUrl);
};

var refreshTipsEmptyImg = function () {
    if ( j$("#tips-list").height() === 0 ) {
        j$("#scenic-empty").show();
    }else{
        j$("#scenic-empty").hide();
    }
};

var addTipEvents = function () {
    var _form = j$("#tips-popup-form"),
        _url = _form.attr('action'),
        _data = {},
        _content = '',
        _popup = j$("#tips-popup"),
        overlay = j$("#overlay"),
        _collectSelectedTags = function (data) {
            var _tag_ids = [],
                _new_tags = [];
            j$("#tips-popup-tag").find(".btn-primary").each(function() {
                var _id = j$(this).attr("data-id");
                if ( j$(this).data("new") == undefined ) {
                    _tag_ids.push(_id);
                    _data["tag_ids"] = _tag_ids;
                }else if ( j$(this).data("new") === 1 ) {
                    _new_tags.push(j$(this).text());
                    _data["new_tags"] = _new_tags;
                };
            });
        };
    _form.on("submit", function(e) {
        e.preventDefault();
        _content = '';
        _data["content"] = _form.find("textarea").val();
        _data["csrfmiddlewaretoken"] = csrf;
        _collectSelectedTags(_data);
        if ( _data["tag_ids"] == undefined && _data["new_tags"] == undefined ) {
            j$("#tips-popup-error").text("请在右侧选择贴士类型");
            return false;
        }else if ( _form.find("textarea").val() == "" ) {
            j$("#tips-popup-error").text("请填写贴士内容");
            _form.find("textarea").focus();
            return false;
        }
        j$.ajax({
            url: _url,
            traditional: true,
            type: 'POST',
            dataType: 'json',
            data: _data,
            success: function (data) {
                if ( data.success ) {
                    _content +='<li data-id="'+ data.tips.id
                             + '"><div class="tips-info fn-clear"><a target="_blank" href="/u/'+ data.user.encrypt_id
                             +'/" class="tips-pic"><img src="'+ data.user.avatar
                             +'" alt=""></a><div class="tips-user"><p><a target="_blank" href="/u/'+ data.user.encrypt_id
                             +'/">'+ data.user.username
                             +'</a></p><p>'+ data.tips.datetime
                             + '</p></div><a href="###" data-like="True" class="tips-tool tips-tool-active"><span></span><b>1</b></a></div><p class="tips-text">'+ data.tips.content
                             + '</p><p class="tip-tags">';
                    j$.each(data.tips.tags, function(j, tag) {
                        _content += '<a data-id="'+ tag.id +'" class="btn" href="###">'+ tag.name +'</a>';
                        modifyTagCount(tag.id, 1);
                    });
                    _content += '</p></li>';
                    j$(_content).prependTo(j$("#tips-list"));
                    bt.misc.hidePopup(_popup);
                    refreshTipsEmptyImg();
                }
            }
        });
    });
    j$("#tips-popup-submit").on("click", function(e) {
        e.preventDefault();
        _form.trigger("submit");
    });
    j$("#tips-popup-cancel").on("click", function(e) {
        e.preventDefault();
        bt.misc.hidePopup(_popup);
        j$("#tips-popup-tag").find("a[data-new]='1'").remove();
        j$("#tips-popup-tag-new").hide();
        j$("#tips-popup-tag-other").show();
    });
    j$("#tips-popup-tag").on("click", "a", function(e) {
        e.preventDefault();
        if ( j$(this).attr("id") == "tips-popup-tag-other" ) {
            j$(this).hide();
            j$("#tips-popup-tag-new").fadeIn("100");
            addNewTags();
        }else{
            j$(this).toggleClass("btn-primary");
        }
    });
};

var delTipEvents = function(){
    var _tipid = 0;
    var _tip;
    var _tags;
    j$("#tips-list").on("click", ".tip-del", function(e) {
        _tip = j$(this).parents("li");
        _tipid = j$(this).parents("li").data("id");
        _tags = [];
        j$(this).siblings("a").each(function(i, el) {
            _tags.push( j$(el).data('id') );
        });
        e.preventDefault();
        bt.misc.showPopup(j$("#tips-del-popup"), function () {

        });
    });
    j$("#tips-del-popup-cancel").on("click", function(e) {
        e.preventDefault();
        bt.misc.hidePopup(j$("#tips-del-popup"));
    });
    j$("#tips-del-popup-yes").on("click", function(e) {
        var _url = "/tips/" + _tipid + "/delete/";
        e.preventDefault();
        bt.misc.hidePopup(j$("#tips-del-popup"));
        j$(_tip).animate({
            opacity: 0},
            500, function() {
            j$(this).slideUp('500');
        });
        j$.post(_url, {csrfmiddlewaretoken: csrf}, function(data) {
            if (!data.success) {
                j$(_tip).fadeIn();
            }else{
                j$.each(_tags, function(i, val) {
                    modifyTagCount(val, -1);
                });
                refreshTipsEmptyImg();
            }
        });
    });
};

var modifyTagCount = function (tagId, count) {
    var _tag = j$("#tag"+tagId);
    var _count = count || 1;
    var _num = parseInt(_tag.find("b").text(), 10);
    _tag.find("b").text(_num+_count);
};

var initTipsEvents = function () {
    addTipEvents();
    delTipEvents();
    j$("#tips-list").on("click", ".tips-tool", function(e) {
        var _liked = j$(this).attr('data-like') === 'True',
            _id = j$(this).parents("li").attr("data-id");
        var _url = "/tips/"+ _id + (_liked ? "/unliked/" : "/liked/");
        if (!BT_USER_ID) {
            bt.misc.redirect_to_login(function () {
                j$.post(_url, {csrfmiddlewaretoken: csrf});
            });
            return false;
        }
        e.preventDefault();
        bt.misc.modifyCount(j$(this).find("b"), _liked? -1: 1);
        if ( _liked ) {
            j$(this).removeClass("tips-tool-active").attr("data-like", "False");
        }else{
            j$(this).addClass("tips-tool-active").attr("data-like", "True");
        }
        j$.post(_url, {csrfmiddlewaretoken: csrf}, function(data) {
            if (!data.success) {
                if ( _liked ) {
                    j$(this).addClass("tips-tool-active").attr("data-like", "True");
                }else{
                    j$(this).removeClass("tips-tool-active").attr("data-like", "False");
                }
            }
        });
    });

    j$("#addtip-btn").on("click", function(e) {
        e.preventDefault();
        if (!BT_USER_ID) {
            bt.misc.redirect_to_login();
            return false;
        }
        j$("#tips-popup").fadeIn();
        j$("#overlay").show();
        bt.misc.showPopup(j$("#tips-popup"), function () {
            j$("#tips-popup").find("textarea").focus();
        });
    });

    j$("#tips-list").on("click", ".btn", function(e) {
        e.preventDefault();
        var _tag = j$(this).attr("data-id");
        if ( j$("#tag"+_tag).length == 0 ) {
            var _name = j$(this).text();
            var _content = '<li class="last"><a data-tag="'+ _tag +'" id="tag'+ _tag +'" href="/scenic/1/6778/tips/more/" title="'+ _name +'"><span class="one-row-ellipsis">'+ _name +'</span><b>000</b><i class="icons"></i></a></li>'
            j$(_content).appendTo("#dropdown-menu");
        }
        j$("#tag"+_tag).trigger("click");
    });
};

var initialize = function () {
    var _targetLat = j$("#content").data("lat");
    var _targetLng = j$("#content").data("lng");
    var _zoom;
    switch (targetType){
        case 1:
        _zoom = 5;
        break;
        case 2:
        _zoom = 8;
        break;
        case 3:
        _zoom = 10;
        break;
        case 5:
        _zoom = 15;
        break;
    }
    var _options = {
        zoom: _zoom,
        maxZoom: 18,
        minZoom: 3,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = bt.gmap.createMap("map-canvas", _options);
    if ( _targetLat ) {
        bt.gmap.setCenter(map, _targetLat, _targetLng);
    }else{
        bt.gmap.zoomToChina(map);
    }
    markers = [];
    infoWindows = [];
    var _iconUrl = STATIC_URL + "img/scenic/marker.png?v=140916";
    var _iconSize = {width: 26, height: 41};
    mapPOIIcons = {
        // Place
        city: {
            origin: new google.maps.Point(0, 252),
            size: _iconSize,
            url: _iconUrl
        },
        cityDark: {
            origin: new google.maps.Point(0, 294),
            size: _iconSize,
            url: _iconUrl
        },
        province: {
            origin: new google.maps.Point(27, 252),
            size: _iconSize,
            url: _iconUrl
        },
        provinceDark: {
            origin: new google.maps.Point(27, 294),
            size: _iconSize,
            url: _iconUrl
        },
        national: {
            origin: new google.maps.Point(54, 252),
            size: _iconSize,
            url: _iconUrl
        },
        nationalDark: {
            origin: new google.maps.Point(54, 294),
            size: _iconSize,
            url: _iconUrl
        },
        // POI
        na: {
            origin: new google.maps.Point(0, 0),
            size: _iconSize,
            url: _iconUrl
        },
        naDark: {
            origin: new google.maps.Point(0, 42),
            size: _iconSize,
            url: _iconUrl
        },
        traffic: {
            origin: new google.maps.Point(0, 82),
            size: _iconSize,
            url: _iconUrl
        },
        trafficDark: {
            origin: new google.maps.Point(0, 124),
            size: _iconSize,
            url: _iconUrl
        },
        business: {
            origin: new google.maps.Point(0, 167),
            size: _iconSize,
            url: _iconUrl
        },
        businessDark: {
            origin: new google.maps.Point(0, 210),
            size: _iconSize,
            url: _iconUrl
        },
        entertainment: {
            origin: new google.maps.Point(27, 0),
            size: _iconSize,
            url: _iconUrl
        },
        entertainmentDark: {
            origin: new google.maps.Point(27, 42),
            size: _iconSize,
            url: _iconUrl
        },
        science_culture: {
            origin: new google.maps.Point(27, 82),
            size: _iconSize,
            url: _iconUrl
        },
        science_cultureDark: {
            origin: new google.maps.Point(27, 124),
            size: _iconSize,
            url: _iconUrl
        },
        sights: {
            origin: new google.maps.Point(27, 167),
            size: _iconSize,
            url: _iconUrl
        },
        sightsDark: {
            origin: new google.maps.Point(27, 210),
            size: _iconSize,
            url: _iconUrl
        },
        streets: {
            origin: new google.maps.Point(54, 0),
            size: _iconSize,
            url: _iconUrl
        },
        streetsDark: {
            origin: new google.maps.Point(54, 42),
            size: _iconSize,
            url: _iconUrl
        },
        experience: {
            origin: new google.maps.Point(54, 84),
            size: _iconSize,
            url: _iconUrl
        },
        experienceDark: {
            origin: new google.maps.Point(54, 126),
            size: _iconSize,
            url: _iconUrl
        },
        hotel: {
            origin: new google.maps.Point(54, 168),
            size: _iconSize,
            url: _iconUrl
        },
        hotelDark: {
            origin: new google.maps.Point(54, 210),
            size: _iconSize,
            url: _iconUrl
        },
        medical: {
            origin: new google.maps.Point(81, 0),
            size: _iconSize,
            url: _iconUrl
        },
        medicalDark: {
            origin: new google.maps.Point(81, 42),
            size: _iconSize,
            url: _iconUrl
        },
        mallDark: {
            origin: new google.maps.Point(81, 84),
            size: _iconSize,
            url: _iconUrl
        },
        mallDarkDark: {
            origin: new google.maps.Point(81, 126),
            size: _iconSize,
            url: _iconUrl
        },
        vehicle_services: {
            origin: new google.maps.Point(81, 168),
            size: _iconSize,
            url: _iconUrl
        },
        vehicle_servicesDark: {
            origin: new google.maps.Point(81, 210),
            size: _iconSize,
            url: _iconUrl
        },
        living_services: {
            origin: new google.maps.Point(108, 0),
            size: _iconSize,
            url: _iconUrl
        },
        living_servicesDark: {
            origin: new google.maps.Point(108, 42),
            size: _iconSize,
            url: _iconUrl
        },
        restaurant: {
            origin: new google.maps.Point(108, 84),
            size: _iconSize,
            url: _iconUrl
        },
        restaurantDark: {
            origin: new google.maps.Point(108, 126),
            size: _iconSize,
            url: _iconUrl
        }
    };
    var tc = document.createElement("div");
    tc.id = "btnToggleMap";
    tc.style.width = "80px";
    tc.style.height = "30px";
    tc.style.lineHeight = "30px";
    tc.style.fontSize = "14px";
    tc.style.border = "1px solid #999";
    tc.style.borderBottom = "3px solid #999";
    tc.style.borderRadius = "4px";
    tc.style.textAlign = "center";
    tc.style.color = "#5c5c5c";
    tc.style.background = "white";
    tc.style.marginLeft = "20px";
    tc.style.padding = "3px 5px";
    tc.style.cursor = "pointer";
    tc.innerHTML = "&lt; 收起面板";
    //= $('<div id="btnToggleMap" style="z-index: 1; width: 80px;text-align: center; padding: 3px 5px;">&lt; 收起面板</div>');
    //toggleControl.index = 1;
    //tc.index = 1;
    google.maps.event.addDomListener(tc , 'click', function() {
        toggleMap();
    });
    if ( targetType != 5 ) {
        map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(tc);
    }
};

var searchPOI = function (q) {
    var _url = " /scenic/"+ targetType +"/"+ targetId +"/search/?";
    var _category = j$(".search-tab li.active").data("category");
    var _data = {q: q, category: _category};
    if ( targetType == 5 ) { _data.poi_pk = true }
    $.get(_url, _data, function(data){
        if(!q){
            $("#search-key").val("");
        }
        if(data.length == 0){
            var html = '<div id="emptySearchResult" class="poi" style="position: absolute; left: 0; right: 0; opacity: 0;"><div class="place">' +
                        '<p class="name">什么也没找到, 换个地方试试</p>' +
                        '<p class="region">或者切换到别的标签看看</p></div></div>';
            $("#search-result").html(html);
            $("#emptySearchResult").animate({"opacity": 1})
        } else {
            showPOI(data);
        }
    }, "json");
};

var showPOI = function (pois) {
    var _r = j$("#search-result");
        _r.html("");
        mapBound = {
            n: -90,
            w: 180,
            e: -180,
            s: 90
        }
        for(i in markers){
            markers[i].setMap(null);
        }
        markers = [];
        infoWindows = [];
        for(i = 0; i < pois.length; i++){
            add2searchResult(pois, i);
            addMarker2map(pois[i]);
        }
        var bound = new google.maps.LatLngBounds(
                new google.maps.LatLng(mapBound.s, mapBound.w),
                new google.maps.LatLng(mapBound.n, mapBound.e)
            )
        map.fitBounds(bound);
};

var add2searchResult = function (pois, i){
    // 将一个搜索到的结果添加到 search-result 下

    var _r = j$("#search-result");
    var _region = [];
    if(pois[i].country){
        _region.push(pois[i].country);
    }
    if(pois[i].province){
        _region.push(pois[i].province);
    }
    if(pois[i].city){
        _region.push(pois[i].city);
    }
    _region = _region.join(', ')
    var _html = '<a onclick="showInfoWindow(' + i + ')"><div class="poi"><div class="tobe"><p class="been-to">' +
    pois[i].been_to + ' 去过</p><p>' +
    pois[i].wish_to + ' 想去</p></div><div class="place"><p class="name">' + (i + 1) + '. ' +
    pois[i].name + '</p><p class="region">' +
    _region + '</p></div></div></a>';
    _r.append($(_html))
};

var addMarker2map = function (i){
    // 记录返回点的bounds, 点的范围
    if(i.lat > mapBound.n){
        mapBound.n = i.lat;
    }
    if(i.lat < mapBound.s){
        mapBound.s = i.lat;
    }
    if(i.lng > mapBound.e){
        mapBound.e = i.lng;
    }
    if(i.lng < mapBound.w){
        mapBound.w = i.lng;
    }

    var iconName = null;
    switch(i['category_id']){
        case 5:
            iconName = 'restaurant'
            break;
        case 6:
            iconName = 'mall'
            break;
        case 10:
            iconName = 'hotel'
            break;
        case 11:
            iconName = 'sights'
            break;
        case 15:
            iconName = 'traffic'
            break;
        case 21:
            iconName = 'entertainment'
            break;
        case 13:
            iconName = 'experience'
            break;
        case 1:
            iconName = 'vehicle_services'
            break;
        case 7:
            iconName = 'living_services'
            break;
        case 9:
            iconName = 'medical'
            break;
        case 12:
            iconName = 'business'
            break;
        case 14:
            iconName = 'science_culture'
            break;
        case 19:
            iconName = 'streets'
            break;
        case 1000:
            iconName = 'na'
            break;
    }

    var markerOptions = {
        map: map,
        position: bt.gmap.createLatLng(i.lat, i.lng)
    }
    iconName ? markerOptions.icon = mapPOIIcons[iconName] : "";

    var marker = new google.maps.Marker(markerOptions);
    marker.iconName = iconName;

    var content = '<div class="info-window" style="height:'+ (i.description ? '290' : '230')  +'px;" id="iw-' + i.encrypt_id + '"><a target="_blank" title="' +
        i.name + '" class="poi" href="'
        + i.url + '"><i class="iw-poi-img" style="background-image: url(';
    if ( i.photo ) {
        content += i.photo;
    }else{
        content += STATIC_URL + 'img/default_trip_cover_508px.png';
    }
    content +=')" ></i><div class="iw-content"><div class="iw-title-panel"><h3 class="iw-title one-row-ellipsis">' +
        i.name + '</h3></div>';
    if ( i.description ) {
        content += '<div class="description">' + i.description + '</div>';
    }else{
        // content += '<div class="description nope">此处暂无具体描述，我们会尽快完善！</div>';
    }
        content += '<span>查看详情</span></div></a></div>';
    var iw = bt.gmap.createInfoWindow({
        content: content,
        maxWidth: 199
    });
    iw._iwId = "iw-" + i.encrypt_id;

    bt.gmap.addListener(marker, 'click', function() {
        for(var j in infoWindows){
            infoWindows[j].close();
        }
        iw.open(map, marker);
        setTimeout(function(){
            infoWindowAdjustWidth($("#" + iw._iwId));
        }, 10);
        // 添加一个扩展的 marker 事件,控制地图的infowindow样式
        var iconName = marker.iconName + "Dark";
        resetMarkerIcon();
        if(mapPOIIcons[iconName]){
            marker.setIcon(mapPOIIcons[iconName]);
            marker._iconSubfix = "Dark";
        }
    });
    markers.push(marker);
    infoWindows.push(iw);
    var resetMarkerIcon = function () {
        for(var i in markers){
            var m = markers[i];
            if(m._iconSubfix == "Dark") {
                m._iconSubfix = "";
                m.setIcon(mapPOIIcons[m.iconName.replace("Dark", "")])
            }
        }
    };
    bt.gmap.addListener(iw,'closeclick',function(){
        resetMarkerIcon();
    });
};

var infoWindowAdjustWidth = function(infoWindow){
    // infoWindow is document Element
    setTimeout(function(){
        // 用异步方法为了先让map渲染infoWindow, 然后在做调整
        var iw = $(infoWindow),
            _width = iw.width(),
            infoParent = iw.parent().parent().parent(),
            gm = j$('.gm-style-iw');
            closebtn = gm.next('div'),
            arrowBg = infoParent.children('div').first().children('div').eq(0),
            arrow = infoParent.children('div').first().children('div').eq(2),
            leftArrow = arrow.children('div').eq(0),
            rightArrow = arrow.children('div').eq(1);
        j$(closebtn).css({
            width: 20,
            height: 20
        }).children('img').attr('src', STATIC_URL + 'img/scenic/icons.png?v=140310').css({
            width: 'auto',
            height: 'auto',
            left: 0,
            top: -256
        });
        j$(gm).css({
            width: _width
        });
        j$(gm).children('div').css({
            width: _width
        });
        j$(arrowBg).css({
            left: (_width/2) - 10
        });
        j$(arrow).css({
            left: (_width/2) - 10
        });
        j$(leftArrow).css({
            width: 22,
            left: -11
        }).children('div').css({
            width: 22,
            '-webkit-transform': 'skewX(45deg)'
        });
        j$(rightArrow).css({
            width: 22,
            left: 10
        }).children('div').css({
            width: 15,
            '-webkit-transform': 'skewX(-45deg)'
        });
        j$(arrowBg).css({
            'border-right-width': 13,
            'border-left-width': 13,
            'border-top-width': 10,
            left: 112
        });
    }, 10)
};

var toggleMap = function () {
    var _btn = $("#btnToggleMap");
    if(_btn.attr("data-status") == "hide"){
        _btn.attr("data-status", "show");
        j$("#btnToggleMap").html("&lt; 收起面板");
        j$(".search-panel").fadeIn();
        j$("#map-panel").animate({"left": "280px"})
    } else {
        _btn.attr("data-status", "hide");
        j$(".search-panel").fadeOut();
        j$("#map-panel").animate({"left": 0})
        j$("#btnToggleMap").html("&gt; 弹出面板");
    }
    bt.gmap.refreshMap(map);
};

var userSearch = function (e){
    if(e.keyCode == 13){
        var q = $("#search-key").val();
        if(q){
            searchPOI(q);
        }
    }
};

var showInfoWindow = function (i){
    for(var j in infoWindows){
        infoWindows[j].close();
    }
    var marker = markers[i];
    infoWindows[i].open(map, marker);
    map.setCenter(marker.getPosition());
    setTimeout(function(){
        infoWindowAdjustWidth($("#" + infoWindows[i]._iwId));
    }, 10)
};

var initMapsEvents = function () {
    bt.gmap.initMapScript(initialize);

    var _tabList = $(".search-tab li");
    _tabList.on("click", function(e){
        $(this).addClass("active").siblings("li").removeClass("active");
        bt.gmap.initMapScript(searchPOI);
    })
    var _initTab = $(".search-tab").data("init-tab");
    var _selectedTab = $('.search-tab li[data-tab="' + _initTab + '"]');
    if(_selectedTab.length){
        _selectedTab.click()
    } else {
        bt.gmap.initMapScript(searchPOI);
    }
};

j$(document).ready(function() {
    initNavEvents();
    initSliderTransition();
    initWishToBeenToStatus();
    initWishToBeenToEvents();
    switch ( column ){
        case "index":{
        }
        break;
        case "photo":{
            loadUrl = j$("#load-more").attr("data-url");
            getMorePhotos(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadPhotos();
            });
        }
        break;
        case "trip":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreTrips(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadTrips();
            });
            initTripCoversEvents();
        }
        break;
        case "city":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreCities(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadCities();
            });
        }
        break;
        case "sight":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreSights(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadSights();
            });
            initDropdownEvents();
        }
        break;
        case "food":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreFoods(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadFoods();
            });
            initDropdownEvents();
        }
        break;
        case "hotel":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreHotels(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadHotels();
            });
            initDropdownEvents();
        }
        break;
        case "mall":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreMalls(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadMalls();
            });
            initDropdownEvents();
        }
        break;
        case "tips":{
            loadUrl = j$("#load-more").attr("data-url");
            getMoreTips(loadUrl);
            j$("#load-more").on("click", function(e) {
                e.preventDefault();
                loadTips();
            });
            initDropdownEvents();
            initTipsEvents();
        }
        break;
        case "map":{
            initMapsEvents();
        }
        break;
    }
});
